package com.gitee.xmhzzz.component.common.enums;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;


/**
  * @ClassName
  * @Description
  * @Author wzq
  * @Date 2023/12/15 17:05
  * @Version 1.0
  */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SortingOrder implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 需要进行排序的字段
     */
    private String column;
    /**
     * 是否正序排列，默认 true
     */
    private boolean asc = true;

    public static SortingOrder asc(String column) {
        return build(column, true);
    }

    public static SortingOrder desc(String column) {
        return build(column, false);
    }

    public static List<SortingOrder> ascs(String... columns) {
        return Arrays.stream(columns).map(SortingOrder::asc).collect(Collectors.toList());
    }

    public static List<SortingOrder> descs(String... columns) {
        return Arrays.stream(columns).map(SortingOrder::desc).collect(Collectors.toList());
    }

    private static SortingOrder build(String column, boolean asc) {
        return new SortingOrder(column, asc);
    }
}

